<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Example  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a title="Example  Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="index.html">Pisth_API Docs</a> (100% documented)</p>
        <p class="header-right"><a href="https://github.com/ColdGrub1384/Pisth"><img src="img/gh.png"/>View on GitHub</a></p>
        <p class="header-right"><a href="dash-feed://https%3A%2F%2Fpisth%2Egithub%2Eio%2Fdocs%2Fapi%2Fdocsets%2FPisth%2Exml"><img src="img/dash.png"/>Install in Dash</a></p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="index.html">Pisth_API Reference</a>
        <img id="carat" src="img/carat.png" />
        Example  Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="Guides.html">Guides</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="example.html">Example</a>
              </li>
              <li class="nav-group-task">
                <a href="getting-started.html">Getting Started</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Classes/Pisth.html">Pisth</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/PisthAPT.html">PisthAPT</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            
            <pre class="highlight swift"><code><span class="k">var</span> <span class="nv">pisth</span><span class="p">:</span> <span class="kt">Pisth</span><span class="o">!</span>
<span class="k">var</span> <span class="nv">pisthAPT</span><span class="p">:</span> <span class="kt">PisthAPT</span><span class="o">!</span>
</code></pre>
<h1 id='appdelegate' class='heading'>AppDelegate</h1>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">UIKit</span>
<span class="kd">import</span> <span class="kt">Pisth_API</span>

<span class="kd">@UIApplicationMain</span>
<span class="kd">class</span> <span class="kt">AppDelegate</span><span class="p">:</span> <span class="kt">UIResponder</span><span class="p">,</span> <span class="nf">UIApplicationDelegate</span> <span class="p">{</span>

    <span class="k">var</span> <span class="nv">window</span><span class="p">:</span> <span class="kt">UIWindow</span><span class="p">?</span>

    <span class="kd">func</span> <span class="nf">application</span><span class="p">(</span><span class="n">_</span> <span class="nv">application</span><span class="p">:</span> <span class="kt">UIApplication</span><span class="p">,</span> <span class="n">didFinishLaunchingWithOptions</span> <span class="nv">launchOptions</span><span class="p">:</span> <span class="p">[</span><span class="kt">UIApplicationLaunchOptionsKey</span><span class="p">:</span> <span class="kt">Any</span><span class="p">]?)</span> <span class="o">-&gt;</span> <span class="nf">Bool</span> <span class="p">{</span>

        <span class="c1">// Setup Pisth API</span>
        <span class="n">pisth</span> <span class="o">=</span> <span class="nf">Pisth</span><span class="p">(</span><span class="nv">message</span><span class="p">:</span> <span class="kc">nil</span> <span class="cm">/* Default message */</span><span class="p">,</span> <span class="nv">urlScheme</span><span class="p">:</span> <span class="nf">URL</span><span class="p">(</span><span class="nv">string</span><span class="p">:</span> <span class="s">"pisth-api://"</span><span class="p">)</span><span class="o">!</span> <span class="cm">/* This app URL scheme */</span><span class="p">)</span>
        <span class="n">pisthAPT</span> <span class="o">=</span> <span class="nf">PisthAPT</span><span class="p">(</span><span class="nv">urlScheme</span><span class="p">:</span> <span class="nf">URL</span><span class="p">(</span><span class="nv">string</span><span class="p">:</span> <span class="s">"pisth-api://"</span><span class="p">)</span><span class="o">!</span> <span class="cm">/* This app's URL Scheme */</span><span class="p">)</span>

        <span class="k">return</span> <span class="kc">true</span>
    <span class="p">}</span>

    <span class="kd">func</span> <span class="nf">application</span><span class="p">(</span><span class="n">_</span> <span class="nv">app</span><span class="p">:</span> <span class="kt">UIApplication</span><span class="p">,</span> <span class="kd">open</span> <span class="nv">url</span><span class="p">:</span> <span class="kt">URL</span><span class="p">,</span> <span class="nv">options</span><span class="p">:</span> <span class="p">[</span><span class="kt">UIApplicationOpenURLOptionsKey</span> <span class="p">:</span> <span class="kt">Any</span><span class="p">]</span> <span class="o">=</span> <span class="p">[:])</span> <span class="o">-&gt;</span> <span class="nf">Bool</span> <span class="p">{</span>

        <span class="k">let</span> <span class="nv">viewController</span> <span class="o">=</span> <span class="p">(</span><span class="kt">UIApplication</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">keyWindow</span><span class="p">?</span><span class="o">.</span><span class="n">rootViewController</span> <span class="k">as?</span> <span class="kt">ViewController</span><span class="p">)</span>

        <span class="k">if</span> <span class="k">let</span> <span class="nv">data</span> <span class="o">=</span> <span class="n">pisth</span><span class="o">.</span><span class="nf">dataReceived</span> <span class="p">{</span>
            <span class="n">viewController</span><span class="p">?</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
            <span class="k">if</span> <span class="k">let</span> <span class="nv">image</span> <span class="o">=</span> <span class="nf">UIImage</span><span class="p">(</span><span class="nv">data</span><span class="p">:</span> <span class="n">data</span><span class="p">)</span> <span class="p">{</span>
                <span class="n">viewController</span><span class="p">?</span><span class="o">.</span><span class="n">imageView</span><span class="o">.</span><span class="n">image</span> <span class="o">=</span> <span class="n">image</span>
            <span class="p">}</span>
        <span class="p">}</span>

        <span class="k">if</span> <span class="k">let</span> <span class="nv">filename</span> <span class="o">=</span> <span class="n">pisth</span><span class="o">.</span><span class="nf">filename</span><span class="p">(</span><span class="nv">fromURL</span><span class="p">:</span> <span class="n">url</span><span class="p">)</span> <span class="p">{</span>
            <span class="n">viewController</span><span class="p">?</span><span class="o">.</span><span class="n">filename</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="n">filename</span>
        <span class="p">}</span>

        <span class="k">return</span> <span class="kc">true</span>
    <span class="p">}</span>

<span class="p">}</span>
</code></pre>
<h1 id='viewcontroller' class='heading'>ViewController</h1>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">UIKit</span>
<span class="kd">import</span> <span class="kt">Pisth_API</span>
<span class="kd">import</span> <span class="kt">Pisth_Shared</span>

<span class="kd">class</span> <span class="kt">ViewController</span><span class="p">:</span> <span class="nf">UIViewController</span> <span class="p">{</span>

    <span class="kd">@IBOutlet</span> <span class="k">weak</span> <span class="k">var</span> <span class="nv">pisthAPTButton</span><span class="p">:</span> <span class="kt">UIButton</span><span class="o">!</span>
    <span class="kd">@IBOutlet</span> <span class="k">weak</span> <span class="k">var</span> <span class="nv">importButton</span><span class="p">:</span> <span class="kt">UIButton</span><span class="o">!</span>
    <span class="kd">@IBOutlet</span> <span class="k">weak</span> <span class="k">var</span> <span class="nv">imageView</span><span class="p">:</span> <span class="kt">UIImageView</span><span class="o">!</span>
    <span class="kd">@IBOutlet</span> <span class="k">weak</span> <span class="k">var</span> <span class="nv">filename</span><span class="p">:</span> <span class="kt">UILabel</span><span class="o">!</span>

    <span class="k">var</span> <span class="nv">data</span><span class="p">:</span> <span class="kt">Data</span><span class="p">?</span>

    <span class="kd">@IBAction</span> <span class="kd">func</span> <span class="nf">share</span><span class="p">(</span><span class="n">_</span> <span class="nv">sender</span><span class="p">:</span> <span class="kt">Any</span><span class="p">)</span> <span class="p">{</span>

        <span class="c1">// Share file</span>

        <span class="k">let</span> <span class="nv">fileURL</span> <span class="o">=</span> <span class="kt">FileManager</span><span class="o">.</span><span class="k">default</span><span class="o">.</span><span class="nf">urls</span><span class="p">(</span><span class="nv">for</span><span class="p">:</span> <span class="o">.</span><span class="n">documentDirectory</span><span class="p">,</span> <span class="nv">in</span><span class="p">:</span> <span class="o">.</span><span class="n">allDomainsMask</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="nf">appendingPathComponent</span><span class="p">(</span><span class="n">filename</span><span class="o">.</span><span class="n">text</span><span class="o">!</span><span class="p">)</span>
        <span class="n">_</span> <span class="o">=</span> <span class="kt">FileManager</span><span class="o">.</span><span class="k">default</span><span class="o">.</span><span class="nf">createFile</span><span class="p">(</span><span class="nv">atPath</span><span class="p">:</span> <span class="n">fileURL</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="nv">contents</span><span class="p">:</span> <span class="n">data</span><span class="p">,</span> <span class="nv">attributes</span><span class="p">:</span> <span class="kc">nil</span><span class="p">)</span>

        <span class="k">let</span> <span class="nv">activityVC</span> <span class="o">=</span> <span class="nf">UIActivityViewController</span><span class="p">(</span><span class="nv">activityItems</span><span class="p">:</span> <span class="p">[</span><span class="n">fileURL</span><span class="p">],</span> <span class="nv">applicationActivities</span><span class="p">:</span> <span class="kc">nil</span><span class="p">)</span>
        <span class="n">activityVC</span><span class="o">.</span><span class="n">popoverPresentationController</span><span class="p">?</span><span class="o">.</span><span class="n">sourceView</span> <span class="o">=</span> <span class="n">sender</span> <span class="k">as?</span> <span class="kt">UIView</span>
        <span class="k">self</span><span class="o">.</span><span class="nf">present</span><span class="p">(</span><span class="n">activityVC</span><span class="p">,</span> <span class="nv">animated</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="kc">nil</span><span class="p">)</span>
    <span class="p">}</span>

    <span class="kd">@IBAction</span> <span class="kd">func</span> <span class="nf">openPisthAPT</span><span class="p">(</span><span class="n">_</span> <span class="nv">sender</span><span class="p">:</span> <span class="kt">Any</span><span class="p">)</span> <span class="p">{</span>

        <span class="c1">// Open connection in Pisth APT</span>
        <span class="k">if</span> <span class="n">pisthAPT</span><span class="o">.</span><span class="nf">canOpen</span> <span class="p">{</span>
            <span class="n">pisthAPT</span><span class="o">.</span><span class="nf">open</span><span class="p">(</span><span class="nv">connection</span><span class="p">:</span> <span class="nf">RemoteConnection</span><span class="p">(</span><span class="nv">host</span><span class="p">:</span> <span class="s">"coldg.ddns.net"</span><span class="p">,</span> <span class="nv">username</span><span class="p">:</span> <span class="s">"pisthtest"</span><span class="p">,</span> <span class="nv">password</span><span class="p">:</span> <span class="s">"pisth"</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="s">"Pisth Test"</span><span class="p">,</span> <span class="nv">path</span><span class="p">:</span> <span class="s">"~"</span><span class="p">,</span> <span class="nv">port</span><span class="p">:</span> <span class="mi">22</span><span class="p">,</span> <span class="nv">useSFTP</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span> <span class="nv">os</span><span class="p">:</span> <span class="s">"Raspbian"</span><span class="p">)</span> <span class="cm">/* Connection to open */</span><span class="p">)</span>
        <span class="p">}</span>
    <span class="p">}</span>

    <span class="kd">@IBAction</span> <span class="kd">func</span> <span class="nf">importFromPisth</span><span class="p">(</span><span class="n">_</span> <span class="nv">sender</span><span class="p">:</span> <span class="kt">Any</span><span class="p">)</span> <span class="p">{</span>

        <span class="c1">// Import file</span>
        <span class="n">pisth</span><span class="o">.</span><span class="nf">importFile</span><span class="p">()</span>
    <span class="p">}</span>

    <span class="k">override</span> <span class="kd">func</span> <span class="nf">viewDidLoad</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">super</span><span class="o">.</span><span class="nf">viewDidLoad</span><span class="p">()</span>

        <span class="c1">// Enable button only if app can import file from Pisth</span>
        <span class="n">importButton</span><span class="o">.</span><span class="n">isEnabled</span> <span class="o">=</span> <span class="n">pisth</span><span class="o">.</span><span class="n">canOpen</span>
    <span class="p">}</span>

<span class="p">}</span>

</code></pre>

          </section>
        </section>
        <section id="footer">
          <p>&copy; 2018 <a class="link" href="" target="_blank" rel="external"></a>. All rights reserved. (Last updated: 2018-04-12)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.1</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
